<!DOCTYPE html>
<html>
<head>
	<!-- Global site tag (gtag.js) - Google Analytics -->
	<script async src="https://www.googletagmanager.com/gtag/js?id='UA-133422980-2"></script>
	<script>
	  window.dataLayer = window.dataLayer || [];
	  function gtag(){dataLayer.push(arguments);}
	  gtag('js', new Date());

	  gtag('config', 'UA-133422980-2');
	</script>

	<meta charset="utf-8">
	<meta http-equiv="x-ua-compatible" content="ie=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<title>
		gem5: Building Android Marshmallow 
	</title>

	<!-- SITE FAVICON -->
	<link rel="shortcut icon" type="image/gif" href="/assets/img/gem5ColorVert.gif"/>

	<link rel="canonical" href="http://localhost:4000/documentation/general_docs/fullsystem/building_android_m">
	<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700,800,600' rel='stylesheet' type='text/css'>
	<link href='https://fonts.googleapis.com/css?family=Muli:400,300' rel='stylesheet' type='text/css'>

	<!-- FAVICON -->
	<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

	<!-- BOOTSTRAP -->
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

	<!-- CUSTOM CSS -->
	<link rel="stylesheet" href="/css/main.css">
</head>


<body>
	<nav class="navbar navbar-expand-md navbar-light bg-light">
  <a class="navbar-brand" href="/">
		<img src="/assets/img/gem5ColorLong.gif" alt="gem5" height=55px>
	</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavDropdown">
    <!-- LIST FOR NAVBAR -->
    <ul class="navbar-nav ml-auto">
      <!-- HOME -->
      <li class="nav-item ">
        <a class="nav-link" href="/">Home</a>
      </li>

      <!-- ABOUT -->
			<li class="nav-item dropdown ">
				<a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
					About
				</a>
				<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <a class="dropdown-item" href="/about">About gem5</a>
          <a class="dropdown-item" href="/publications">Publications</a>
          <a class="dropdown-item" href="/governance">Governance</a>
				</div>
			</li>

      <!-- DOCUMENTATION -->
			<li class="nav-item dropdown active">
				<a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
					Documentation
				</a>
				<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
					<!-- Pull navigation from _data/documentation.yml -->
					
            <a class="dropdown-item" href="/documentation">gem5 documentation</a>
					
            <a class="dropdown-item" href="/documentation/learning_gem5/introduction">Learning gem5</a>
					
            <a class="dropdown-item" href="http://doxygen.gem5.org/release/current/index.html">gem5 Doxygen</a>
					
            <a class="dropdown-item" href="/documentation/reporting_problems">Reporting Problems</a>
					
				</div>
			</li>

      <!-- EVENTS -->
			<li class="nav-item dropdown ">
        <a class="nav-link" href="/events/">Events</a>
			</li>

      <!-- CONTRIBUTING -->
      <li class="nav-item ">
        <a class="nav-link" href="/contributing">Contributing</a>
      </li>

      <!-- BLOG -->
      <li class="nav-item ">
        <a class="nav-link" href="/blog">Blog</a>
      </li>

      <!-- SEARCH -->
			<li class="nav-item ">
        <a class="nav-link" href="/search">Search</a>
      </li>
    </ul>
  </div>
</nav>

	<main>
		<div class="sidenav-top">
  <div class="sidenav-brand bg-light">
    <a href="/"><img src="/assets/img/gem5ColorLong.gif" height="55px"></a>
  </div>
  <div class="search">
    <form action="/search" method="get">
      <!-- <label for="search-box"><i class="fa fa-search"></i></label> -->
      <input type="text" name="query">
      <button type="submit" name="submit"><i class="fa fa-search"></i></button>
    </form>
  </div>
</div>
<div class="sidenav">
  <!-- Pull navigation from _data/documentation.yml -->
  
    
    
      <a class="item" href="/documentation" role="button" aria-expanded="false" aria-controls="collapseExample">
        gem5 documentation
      </a>
      <div class="collapse " id="gem5_documentation">
        
      </div>
    
      <a class="item" href="/documentation/general_docs/development/coding_style/" role="button" aria-expanded="false" aria-controls="collapseExample">
        Code Style
      </a>
      <div class="collapse " id="code_style">
        
      </div>
    
      <a class="item" data-toggle="collapse" href="#building" role="button" aria-expanded="false" aria-controls="collapseExample">
        Building
      </a>
      <div class="collapse " id="building">
        
          <a class="subitem " href="/documentation/general_docs/building">Building</a>
        
          <a class="subitem " href="/documentation/general_docs/building/EXTRAS">Building EXTRAS</a>
        
      </div>
    
      <a class="item" data-toggle="collapse" href="#doxygen-docs" role="button" aria-expanded="false" aria-controls="collapseExample">
        Doxygen
      </a>
      <div class="collapse " id="doxygen-docs">
        
          <a class="subitem " href="http://doxygen.gem5.org/develop/index.html">Develop Branch</a>
        
          <a class="subitem " href="http://doxygen.gem5.org/release/v19-0-0-0/index.html">v19.0.0.0</a>
        
      </div>
    
      <a class="item" data-toggle="collapse" href="#fullsystem" role="button" aria-expanded="false" aria-controls="collapseExample">
        Full System
      </a>
      <div class="collapse show" id="fullsystem">
        
          <a class="subitem " href="/documentation/general_docs/fullsystem/disks">Creating Disk Images</a>
        
          <a class="subitem " href="/documentation/general_docs/fullsystem/devices">Devices</a>
        
          <a class="subitem " href="/documentation/general_docs/fullsystem/m5term">m5term</a>
        
          <a class="subitem " href="/documentation/general_docs/fullsystem/building_arm_kernel">Building Linux ARM Kernel</a>
        
          <a class="subitem active" href="/documentation/general_docs/fullsystem/building_android_m">Building Android Marshmallow</a>
        
          <a class="subitem " href="/documentation/general_docs/fullsystem/guest_binaries">Guest binaries</a>
        
      </div>
    
      <a class="item" data-toggle="collapse" href="#memory_system" role="button" aria-expanded="false" aria-controls="collapseExample">
        Memory System
      </a>
      <div class="collapse " id="memory_system">
        
          <a class="subitem " href="/documentation/general_docs/memory_system/">Memory System</a>
        
          <a class="subitem " href="/documentation/general_docs/memory_system/gem5_memory_system">gem5 Memory System</a>
        
          <a class="subitem " href="/documentation/general_docs/memory_system/replacement_policies">Replacement Policies</a>
        
          <a class="subitem " href="/documentation/general_docs/memory_system/indexing_policies">Indexing Policies</a>
        
          <a class="subitem " href="/documentation/general_docs/memory_system/classic-coherence-protocol">Classic memory system coherence</a>
        
          <a class="subitem " href="/documentation/general_docs/memory_system/classic_caches">Classic caches</a>
        
      </div>
    
      <a class="item" data-toggle="collapse" href="#ruby" role="button" aria-expanded="false" aria-controls="collapseExample">
        Ruby Memory System
      </a>
      <div class="collapse " id="ruby">
        
          <a class="subitem " href="/documentation/general_docs/ruby">Ruby</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/cache-coherence-protocols">Cache Coherence Protocols</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/garnet-2">Garnet 2.0</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/MOESI_CMP_directory">MOESI CMP directory</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/garnet_synthetic_traffic">Garnet Synthetic Traffic</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/slicc">SLICC</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/MI_example">MI example</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/Garnet_standalone">Garnet standalone</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/interconnection-network">Interconnection network</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/MOESI_hammer">MOESI hammer</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/MOESI_CMP_token">MOESI CMP token</a>
        
          <a class="subitem " href="/documentation/general_docs/ruby/MESI_Two_Level">MESI two level</a>
        
          <a class="subitem " href="/documentation/general_docs/memory_system/replacement_policies">Replacement Policies</a>
        
      </div>
    
      <a class="item" data-toggle="collapse" href="#cpu_models" role="button" aria-expanded="false" aria-controls="collapseExample">
        CPU Models
      </a>
      <div class="collapse " id="cpu_models">
        
          <a class="subitem " href="/documentation/general_docs/cpu_models/SimpleCPU">SimpleCPU</a>
        
          <a class="subitem " href="/documentation/general_docs/cpu_models/O3CPU">O3CPU</a>
        
          <a class="subitem " href="/documentation/general_docs/cpu_models/TraceCPU">TraceCPU</a>
        
          <a class="subitem " href="/documentation/general_docs/cpu_models/minor_cpu">Minor CPU Model</a>
        
          <a class="subitem " href="/documentation/general_docs/cpu_models/execution_basics">Execution Basics</a>
        
          <a class="subitem " href="/documentation/general_docs/cpu_models/visualization">Visualization</a>
        
      </div>
    
      <a class="item" href="/documentation/general_docs/m5ops" role="button" aria-expanded="false" aria-controls="collapseExample">
        M5ops
      </a>
      <div class="collapse " id="m5ops">
        
      </div>
    
      <a class="item" href="/documentation/general_docs/checkpoints" role="button" aria-expanded="false" aria-controls="collapseExample">
        Checkpoints
      </a>
      <div class="collapse " id="checkpoints">
        
      </div>
    
      <a class="item" data-toggle="collapse" href="#directed_testers" role="button" aria-expanded="false" aria-controls="collapseExample">
        Directed Testers
      </a>
      <div class="collapse " id="directed_testers">
        
          <a class="subitem " href="/documentation/general_docs/debugging_and_testing/directed_testers/garnet_synthetic_traffic">Garnet Synthetic Traffic</a>
        
          <a class="subitem " href="/documentation/general_docs/debugging_and_testing/directed_testers/ruby_random_tester">Ruby Random Tester</a>
        
      </div>
    
      <a class="item" data-toggle="collapse" href="#debugging" role="button" aria-expanded="false" aria-controls="collapseExample">
        Debugging
      </a>
      <div class="collapse " id="debugging">
        
          <a class="subitem " href="/documentation/general_docs/debugging_and_testing/debugging/trace_based_debugging">Trace-based Debugging</a>
        
          <a class="subitem " href="/documentation/general_docs/debugging_and_testing/debugging/debugger_based_debugging">Debugger-based Debugging</a>
        
          <a class="subitem " href="/documentation/general_docs/debugging_and_testing/debugging/debugging_simulated_code">Debugging Simulated Code</a>
        
          <a class="subitem " href="/documentation/reporting_problems">Reporting Problems</a>
        
      </div>
    
      <a class="item" data-toggle="collapse" href="#architecture_support" role="button" aria-expanded="false" aria-controls="collapseExample">
        Architecture Support
      </a>
      <div class="collapse " id="architecture_support">
        
          <a class="subitem " href="/documentation/general_docs/architecture_support/">Architecture Support</a>
        
          <a class="subitem " href="/documentation/general_docs/architecture_support/arm_implementation/">ARM Implementation</a>
        
          <a class="subitem " href="/documentation/general_docs/architecture_support/isa_parser/">ISA Parser</a>
        
          <a class="subitem " href="/documentation/general_docs/architecture_support/x86_microop_isa/">X86 microop ISA</a>
        
      </div>
    
      <a class="item" href="/documentation/general_docs/thermal_model" role="button" aria-expanded="false" aria-controls="collapseExample">
        Power and Thermal Model
      </a>
      <div class="collapse " id="">
        
      </div>
    
      <a class="item" href="/documentation/general_docs/compiling_workloads/" role="button" aria-expanded="false" aria-controls="collapseExample">
        Compiling Workloads
      </a>
      <div class="collapse " id="compiling_workloads">
        
      </div>
    
      <a class="item" href="/documentation/general_docs/statistics/" role="button" aria-expanded="false" aria-controls="collapseExample">
        Stats Package
      </a>
      <div class="collapse " id="statistics">
        
      </div>
    
    
  
    
  
    
  
    
  
</div>


<div class="container" id="doc-container">
  <div class="edit"><a href="https://gem5.googlesource.com/public/gem5-website/+/refs/heads/master/README.md">Edit this page</a></div>
  
  

  <br>
  <h1 id="building-android-marshmallow">Building Android Marshmallow</h1>

<p>This guide gives detailed step-by-step instructions on building an Android Marshmallow image along with a working kernel and .dtb file that work with gem5.</p>

<h2 id="overview">Overview</h2>
<p>To successfully run Android in gem5, an image, a compatible kernel and a device tree blob.dtb file configured for the simulator are necessary. This guide shows how to build Android Marshmallow 32bit version using a 3.14 kernel with Mali support. An extra section will be added in the future on how to build the 4.4 kernel with Mali.</p>

<h2 id="pre-requisites">Pre-requisites</h2>
<p>This guide assumes a 64-bit system running 14.04 LTS Ubuntu. Before starting it is important first to set up our system correctly. To do this the following packages need to be installed through shell.</p>

<p><strong>Tip: Always check for the up-to-date prerequisites at the Android build page.</strong></p>

<p>Update and install all the dependencies. This can be done with the following commands:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get update

sudo apt-get install openjdk-7-jdk git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip
</code></pre></div></div>

<p>Also, make sure to have repo correctly installed <a href="https://source.android.com/source/downloading.html#installing-repo">(instructions here)</a>.</p>

<p>Ensure that the default JDK is OpenJDK 1.7:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>javac -version
</code></pre></div></div>

<p>To cross-compile the kernel (32bit) and for the device tree we will need the following packages to be installed:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get install gcc-arm-linux-gnueabihf device-tree-compiler
</code></pre></div></div>

<p>Before getting started, as a final step make sure to have the gem5 binaries and busybox for 32-bit ARM.</p>

<p>For the gem5 binaries just do the following starting from your gem5 directory:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cd util/m5
make -f Makefile.arm
cd ../term
make
cd ../../system/arm/simple_bootloader/
make
</code></pre></div></div>

<p>For busybox you can find the guide <a href="http://wiki.beyondlogic.org/index.php?title=Cross_Compiling_BusyBox_for_ARM">here</a>.</p>

<h2 id="building-android">Building Android</h2>
<p>We build Android Marshmallow using an AOSP running build based on the release for the Pixel C. The AOSP provides <a href="https://source.android.com/source/build-numbers.html#source-code-tags-and-builds">other builds</a>, which are untested with this guide.</p>

<p><strong>Tip: Synching with repo will take a long time. Use the -jN flag to speed up the make process, where N is the number of parallel jobs to run.</strong></p>

<p>Make a directory and pull the Android repository:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mkdir android
cd android
repo init --depth=1 -u https://android.googlesource.com/platform/manifest -b android-6.0.1_r63
repo sync -c -jN
</code></pre></div></div>

<p>Before you start the AOSP build, you will need to make one change to the build system to enable building libion.so, which is used by the Mali driver. Edit the file <code class="highlighter-rouge">aosp/system/core/libion/Android.mk</code> to change <code class="highlighter-rouge">LOCAL_MODULE_TAGS</code> for libion from ‘optional’ to ‘debug’. Here is the output of <code class="highlighter-rouge">repo diff</code>:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  --- a/system/core/libion/Android.mk
  +++ b/system/core/libion/Android.mk
  @@ -3,7 +3,7 @@ LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  LOCAL_SRC_FILES := ion.c
  LOCAL_MODULE := libion
  -LOCAL_MODULE_TAGS := optional
  +LOCAL_MODULE_TAGS := debug
  LOCAL_SHARED_LIBRARIES := liblog
  LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/kernel-headers
  LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
  $(LOCAL_PATH)/kernel-headers
</code></pre></div></div>

<p>Source the environment setup and build Android:</p>

<p><strong>Tip: For root access and “debuggability” [sic] we choose userdebug. Build can be done in different modes as seen</strong> <a href="https://source.android.com/source/building.html#choose-a-target">here</a>.
<strong>Tip: Making Android will take a long time. Use the -jN flag to speed up the make process, where N is the number of parallel jobs to run.</strong></p>

<p><strong><em>Make sure to do this in a bash shell.</em></strong></p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>source build/envsetup.sh
lunch aosp_arm-userdebug
make -jN
</code></pre></div></div>

<h2 id="creating-an-android-image">Creating an Android image</h2>

<p>After a successful build, we create an image of Android and add the init files and binaries that configure the system for gem5. The following example creates a 3GB image.</p>

<p><strong>Tip: If you want to add applications or data, make the image large enough to fit the build and anything else that is meant to be written into it.</strong></p>

<p>Create an empty image to flash the Android build and attach the image to a loopback device:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dd if=/dev/zero of=myimage.img bs=1M count=2560
sudo losetup /dev/loop0 myimage.img
</code></pre></div></div>

<p>We now need to create three partitions: AndroidRoot (1.5GB), AndroidData (1GB), and AndroidCache (512MB).</p>

<p>First, partition the device:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo fdisk /dev/loop0
</code></pre></div></div>

<p>Update the partition table:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo partprobe /dev/loop0
</code></pre></div></div>

<p>Name the partitions / Define filesystem as ext4:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo mkfs.ext4 -L AndroidRoot /dev/loop0p1
sudo mkfs.ext4 -L AndroidData /dev/loop0p
sudo mkfs.ext4 -L AndroidCache /dev/loop0p3
</code></pre></div></div>

<p>Mount the Root partition to a directory:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo mkdir -p /mnt/androidRoot
sudo mount /dev/loop0p1 /mnt/androidRoot
</code></pre></div></div>

<p>Load the build to the partition:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cd /mnt/androidRoot
sudo zcat &lt;path/to/build/android&gt;/out/target/product/generic/ramdisk.img | sudo cpio -i
sudo mkdir cache
sudo mkdir /mnt/tmp
sudo mount -oro,loop &lt;path/to/build/android&gt;/out/target/product/generic/system.img /mnt/tmp
sudo cp -a /mnt/tmp/* system/
sudo umount /mnt/tmp
</code></pre></div></div>

<p>Download and unpack the <a href="http://dist.gem5.org/dist/current/arm/kitkat-overlay.tar.bz2">overlays</a> that are necessary from the <a href="http://old.gem5.org/Android_KitKat.html" title="wikilink">gem5 Android KitKat page</a> and make the following changes to the <code class="highlighter-rouge">init.gem5.rc</code> file. Here is the output of <code class="highlighter-rouge">repo diff</code>:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  --- /kitkat_overlay/init.gem5.rc
  +++ /m_overlay/init.gem5.rc
  @@ -1,21 +1,13 @@
  +
   on early-init
       mount debugfs debugfs /sys/kernel/debug
  
   on init
  -    export LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/vendor/lib/egl
  -
  -    # See storage config details at http://source.android.com/tech/storage/
  -    mkdir /mnt/media_rw/sdcard 0700 media_rw media_rw
  -    mkdir /storage/sdcard 0700 root root
  +    # Support legacy paths
  +    symlink /sdcard /mnt/sdcard
       chmod 0666 /dev/mali0
       chmod 0666 /dev/ion
  -
  -    export EXTERNAL_STORAGE /storage/sdcard
  -
  -    # Support legacy paths
  -    symlink /storage/sdcard /sdcard
  -    symlink /storage/sdcard /mnt/sdcard
  
   on fs
       mount_all /fstab.gem5
  @@ -60,7 +52,6 @@
       group root
       oneshot
  
  -# fusewrapped external sdcard daemon running as media_rw (1023)
  -service fuse_sdcard /system/bin/sdcard -u 1023 -g 1023 -d
  /mnt/media_rw/sdcard /storage/sdcard
  +service fingerprintd /system/bin/fingerprintd
       class late_start
  -    disabled
  +    user system
</code></pre></div></div>

<p>Add the Android overlays and configure their permissions:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo cp -r &lt;path/to/android/overlays&gt;/* /mnt/androidRoot/
sudo chmod ug+x /mnt/androidRoot/init.gem5.rc
/mnt/androidRoot/gem5/postboot.sh
</code></pre></div></div>

<p>Add the m5 and busybox binaries under the sbin directory and make them executable:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo cp &lt;path/to/gem5&gt;/util/m5/m5 /mnt/androidRoot/sbin
sudo cp &lt;path/to/busybox&gt;/busybox /mnt/androidRoot/sbin
sudo chmod a+x /mnt/androidRoot/sbin/busybox /mnt/androidRoot/sbin/m5
</code></pre></div></div>

<p>Make the directories readable and searchable:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo chmod a+rx /mnt/androidRoot/sbin/ /mnt/androidRoot/gem5/
</code></pre></div></div>

<p>Remove the boot animation:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo rm /mnt/androidRoot/system/bin/bootanimation
</code></pre></div></div>

<p>Download and unpack the Mali drivers, for gem5 Android 4.4, from <a href="http://malideveloper.arm.com/resources/drivers/arm-mali-midgard-gpu-user-space-drivers/">here</a>. Then, make the directories for the drivers and copy them:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo mkdir -p /mnt/androidRoot/system/vendor/lib/egl
sudo mkdir -p /mnt/androidRoot/system/vendor/lib/hw
sudo cp &lt;path/to/userspace/Mali/drivers&gt;/lib/egl/libGLES_mali.so /mnt/androidRoot/system/vendor/lib/egl
sudo cp &lt;path/to/userspace/Mali/drivers&gt;/lib/hw/gralloc.default.so /mnt/androidRoot/system/vendor/lib/hw
</code></pre></div></div>

<p>Change the permissions</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo chmod 0755 /mnt/androidRoot/system/vendor/lib/hw
sudo chmod 0755 /mnt/androidRoot/system/vendor/lib/egl
sudo chmod 0644 /mnt/androidRoot/system/vendor/lib/egl/libGLES_mali.so
sudo chmod 0644 /mnt/androidRoot/system/vendor/lib/hw/gralloc.default.so
</code></pre></div></div>

<p>Unmount and remove loopback device:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cd /..
sudo umount /mnt/androidRoot
sudo losetup -d /dev/loop0
</code></pre></div></div>

<h2 id="building-the-kernel-314">Building the Kernel (3.14)</h2>

<p>After successfully setting up the image, a compatible kernel needs to be built and a .dtb file generated.</p>

<p>Clone the repository containing the gem5 specific kernel:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone -b ll_20140416.0-gem5 https://github.com/gem5/linux-arm-gem5.git
</code></pre></div></div>

<p>Make the following changes to the kernel gem5 config file at <code class="highlighter-rouge">&lt;path/to/kernel/repo&gt;/arch/arm/configs/vexpress_gem5_defconfig</code>. Here is the output of <code class="highlighter-rouge">repo diff</code>:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  --- a/arch/arm/configs/vexpress_gem5_defconfig
  +++ b/arch/arm/configs/vexpress_gem5_defconfig
  @@ -200,4 +200,15 @@ CONFIG_EARLY_PRINTK=y
  CONFIG_DEBUG_PREEMPT=n
  # CONFIG_CRYPTO_ANSI_CPRNG is not set
  # CONFIG_CRYPTO_HW is not set
  +CONFIG_MALI_MIDGARD=y
  +CONFIG_MALI_MIDGARD_DEBUG_SYS=y
  +CONFIG_ION=y
  +CONFIG_ION_DUMMY=y
  CONFIG_BINARY_PRINTF=y
  +CONFIG_NET_9P=y
  +CONFIG_NET_9P_VIRTIO=y
  +CONFIG_9P_FS=y
  +CONFIG_9P_FS_POSIX_ACL=y
  +CONFIG_9P_FS_SECURITY=y
  +CONFIG_VIRTIO_BLK=y
  +CONFIG_VMSPLIT_3G=y
  +CONFIG_DNOTIFY=y
  +CONFIG_FUSE_FS=y
</code></pre></div></div>

<p>For the device tree, add the Mali GPU device and increase the memory to 1.8GB. Do this with the following changes at <code class="highlighter-rouge">&lt;path/to/kernel/repo&gt;/arch/arm/boot/dts/vexpress-v2p-ca15-tc1-gem5.dts.</code> Here is the output of <code class="highlighter-rouge">repo diff</code>:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  --- a/arch/arm/boot/dts/vexpress-v2p-ca15-tc1-gem5.dts
  +++ b/arch/arm/boot/dts/vexpress-v2p-ca15-tc1-gem5.dts
  @@ -45,7 +45,7 @@
  
           memory@80000000 {
                   device_type = "memory";
  -                reg = &lt;0 0x80000000 0 0x40000000&gt;;
  +                reg = &lt;0 0x80000000 0 0x74000000&gt;;
           };
  
          hdlcd@2b000000 {
  @@ -59,6 +59,14 @@
  //                mode = "3840x2160MR-16@60"; // UHD4K mode string
                    framebuffer = &lt;0 0x8f000000 0 0x01000000&gt;;
            };
  +
  +    gpu@0x2d000000 {
  +        compatible = "arm,mali-midgard";
  +        reg = &lt;0 0x2b400000 0 0x4000&gt;;
  +        interrupts = &lt;0 86 4&gt;, &lt;0 87 4&gt;, &lt;0 88 4&gt;;
  +        interrupt-names = "JOB", "MMU", "GPU";
  +    };
  +
  /*
          memory-controller@2b0a0000 {
                    compatible = "arm,pl341", "arm,primecell";
</code></pre></div></div>

<p>Download and unpack the userspace matching Mali kernel drivers for gem5 from [http://malideveloper.arm.com/resources/drivers/open-source-mali-midgard-gpu-kernel-drivers/ here]. Copy them to the gpu driver directory:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cp -r &lt;path/to/kernelspace/Mali/drivers&gt;/driver/product/kernel/drivers/gpu/arm/ drivers/gpu
</code></pre></div></div>

<p>Change the following in <code class="highlighter-rouge">&lt;path/to/kernelspace/Mali/drivers&gt;/drivers/video/Kconfig</code> and <code class="highlighter-rouge">&lt;path/to/kernelspace/Mali/drivers&gt;/drivers/gpu/Makefile</code> based on the following diffs:</p>

<p>Here is the output of the Kconfig <code class="highlighter-rouge">repo diff</code>:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  --- a/drivers/video/Kconfig
  +++ b/drivers/video/Kconfig
  @@ -23,6 +23,8 @@ source "drivers/gpu/host1x/Kconfig"
  
  source "drivers/gpu/drm/Kconfig"
  
  +source "drivers/gpu/arm/Kconfig"
  +
   config VGASTATE
          tristate
          default n
</code></pre></div></div>

<p>Here is the output of the drivers/gpu/Makefile <code class="highlighter-rouge">repo diff</code>:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  --- a/drivers/gpu/Makefile
  +++ b/drivers/gpu/Makefile
  @@ -1,2 +1,2 @@
  -obj-y                += drm/ vga/
  +obj-y                += drm/ vga/ arm/
</code></pre></div></div>

<p>Finally, build the kernel and the .dtb file.</p>

<p><strong>Tip: Use the -jN flag to speed up the make process, where N is the number of parallel jobs to run.</strong></p>

<p>Build the kernel:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>make CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm vexpress_gem5_defconfig
make CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm vmlinux -jN
</code></pre></div></div>

<p>Create the .dtb file:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dtc -I dts -O dtb arch/arm/boot/dts/vexpress-v2p-ca15-tc1-gem5.dts &gt; vexpress-v2p-ca15-tc1-gem5.dtb
</code></pre></div></div>

<h2 id="testing-the-build">Testing the build</h2>

<p>Make the following changes to example/fs.py. Here is the output <code class="highlighter-rouge">repo diff</code>:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  --- a/configs/example/fs.py Thu Jun 02 20:34:39 2016 +0100
  +++ b/configs/example/fs.py Fri Jun 10 15:37:29 2016 -0700
  @@ -144,6 +144,13 @@
       if is_kvm_cpu(TestCPUClass) or is_kvm_cpu(FutureClass):
           test_sys.vm = KvmVM()
  
  +    test_sys.gpu = NoMaliGpu(
  +        gpu_type="T760",
  +        ver_maj=0, ver_min=0, ver_status=1,
  +        int_job=118, int_mmu=119, int_gpu=120,
  +        pio_addr=0x2b400000,
  +        pio=test_sys.membus.master)
  +
      if options.ruby:
          # Check for timing mode because ruby does not support atomic accesses
          if not (options.cpu_type == "detailed" or options.cpu_type == "timing"):
</code></pre></div></div>

<p>And the changes to FS config to either enable or disable software rendering.</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  --- a/configs/common/FSConfig.py Thu Jun 02 20:34:39 2016 +0100
  +++ b/configs/common/FSConfig.py Thu Jun 16 10:23:44 2016 -0700
  @@ -345,7 +345,7 @@
  
             # release-specific tweaks
             if 'kitkat' in mdesc.os_type():
  -                cmdline += " androidboot.hardware=gem5 qemu=1 qemu.gles=0 " + \
  +                cmdline += " androidboot.hardware=gem5 qemu=1 qemu.gles=1 " + \
                            "android.bootanim=0"
  
         self.boot_osflags = fillInCmdline(mdesc, cmdline
</code></pre></div></div>

<p>Set the following M5_PATH:</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>M5_PATH=. build/ARM/gem5.opt configs/example/fs.py --cpu-type=atomic --mem-type=SimpleMemory --os-type=android-kitkat --disk-image=myimage.img --machine-type=VExpress_EMM --dtb-filename=vexpress-v2p-ca15-tc1-gem5.dtb -n 1 --mem-size=1800MB
</code></pre></div></div>

<h2 id="building-older-versions-of-android">Building older versions of Android</h2>

<p>gem5 has support for running even older versions of Android like KitKat. The documentation to do so, as well as the necessary drivers and files required, can be found on the old wiki <a href="http://old.gem5.org/Android_KitKat.html">here</a>.</p>

  <br>

  <!-- RETRIVE PREVIOUS PAGE LINK -->
  
    
  
    
  
    
  
    
  

  <!-- RETRIEVE NEXT PAGE LINK -->
  
    
  
    
  
    
  
    
  


  <div class="navbuttons">
    
      <a href=""><button type="button" class="btn btn-outline-primary">PREVIOUS</button></a>
    

    
      <a href=""><button type="button" class="btn btn-outline-primary">NEXT</button></a>
    
  </div>
</div>

	</main>
	<footer class="page-footer">
	<div class="container">
		<div class="row">

			<div class="col-12 col-sm-4">
				<p>gem5</p>
				<p><a href="/about">About</a></p>
				<p><a href="/publications">Publications</a></p>
				<p><a href="/contributing">Contributing</a></p>
				<p><a href="/governance">Governance</a></p>
			<br></div>

			<div class="col-12 col-sm-4">
				<p>Docs</p>
				<p><a href="/documentation">Documentation</a></p>
				<p><a href="http://gem5.org/Documentation">Old Documentation</a></p>
				<p><a href="https://gem5.googlesource.com/public/gem5">Source</a></p>
			<br></div>

			<div class="col-12 col-sm-4">
				<p>Help</p>
				<p><a href="/search">Search</a></p>
				<p><a href="/mailing_lists">Mailing Lists</a></p>
				<p><a href="https://gem5.googlesource.com/public/gem5-website/+/refs/heads/master/README.md">Website Source</a></p>
			<br></div>

		</div>
	</div>
</footer>


	<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
	<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
	<script src="https://unpkg.com/commentbox.io/dist/commentBox.min.js"></script>

	<script>
	  // When the user scrolls down 20px from the top of the document, show the button
	  window.onscroll = function() {scrollFunction()};

	  function scrollFunction() {
	      if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 20) {
	          document.getElementById("myBtn").style.display = "block";
	      } else {
	          document.getElementById("myBtn").style.display = "none";
	      }
	  }

	  // When the user clicks on the button, scroll to the top of the document
	  function topFunction() {
	      document.body.scrollTop = 0;
	      document.documentElement.scrollTop = 0;
	  }

		import commentBox from 'commentbox.io';
		// or
		const commentBox = require('commentbox.io');
		// or if using the CDN, it will be available as a global "commentBox" variable.

		commentBox('my-project-id');

	</script>

</body>


</html>
